# No missings in outcomes

# Impute covariates

# Impute covariates that were only asked from VHTs (sample included VHTs and womens' representatives)

temporary_data <- mice(data = vht_ml[vht_ml$vht_naba ==1 ,c(covariates_only_vhts,covariates_all_healthworkers)],m = 1,seed = 1234567)
temporary_data <- mice::complete(temporary_data)

vht_ml[vht_ml$vht_naba ==1 ,c(covariates_only_vhts,covariates_all_healthworkers)] <- temporary_data[,c(covariates_only_vhts,covariates_all_healthworkers)]
stopifnot(all(apply(vht_ml[vht_ml$vht_naba ==1 ,c(covariates_only_vhts,covariates_all_healthworkers)],2,function(x)sum(is.na(x))) == 0))


# Impute all covariates

temporary_data <- mice(data = vht_ml[,covariates_all_healthworkers],m = 1,seed = 1234567)
temporary_data <- complete(temporary_data)

vht_ml[,covariates_all_healthworkers] <- temporary_data[,covariates_all_healthworkers]
stopifnot(all(apply(vht_ml[,covariates_all_healthworkers],2,function(x)sum(is.na(x))) == 0))

rm(temporary_data)
